﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    .one {
      width: 100px;
      height: 100px;
      background: red;
    }

  </style>
</head>

<body>
  <div class="one two three"></div>
</body>
<script>
  var box = document.querySelector('.one');
  // console.log(box.classList) //获取到所有的class名
  //检查一个东西的类型是什么用typeof
  console.log(typeof (box.classList)); //这是对象 伪数组
  //伪数组是有下标但是数组上的一些方法不能使用
  box.classList.add('two')
  // console.log(box.classList)  //重复的class添加不上
  box.classList.add('four')
  // console.log(box.classList)  //添加一个新的class名
  box.classList.remove('two');
  // console.log(box.classList)  //删除掉其中给一个class名
  box.classList.toggle('five')
  console.log(box.classList) //添加不重复的class名
  box.classList.toggle('three')
  console.log(box.classList) //删除掉重复的名

</script>

</html>
